import React from "react";
import { Form, Button, Input, Toast } from "antd-mobile/2x";
import { useHistory } from "react-router-dom";
import api from "../../api/user";
export default function Login() {
  const { push } = useHistory();
  const onFinish = (values: any) => {
    api.apiLogin({ ...values }).then((res: any) => {
      if (res.status === 200) {
        localStorage.setItem("token", res.body.token);
        Toast.show({
          icon: "success",
          content: res.description,
        });
        push("/");
      }
    });
  };
  return (
    <div>
      {" "}
      <Form
        onFinish={onFinish}
        layout="horizontal"
        footer={
          <Button block type="submit" color="success">
            登录
          </Button>
        }
      >
        <Form.Item
          name="username"
          label="账号"
          rules={[{ required: true, message: "账号不能为空" }]}
        >
          <Input placeholder="请输入姓名" />
        </Form.Item>
        <Form.Item
          name="password"
          label="密码"
          rules={[{ required: true, message: "密码不能为空" }]}
        >
          <Input type="password" placeholder="请输入姓名" />
        </Form.Item>
      </Form>
    </div>
  );
}
